<template>
  <div class="city top-page">
    <div class="top">
      <!-- 1、搜索框 -->
      <van-search
        v-model="searchValue"
        show-action
        placeholder="城市 / 区域 / 位置"
        shape="round"
        @cancel="cancelClick"
      />
      <!-- 2、tab切换 -->
      <van-tabs v-model:active="tabAcitve" color="#ff9854">
        <template v-for="(value, key, index) in allCities" :key="key">
          <van-tab :title="value.title" :name="key"></van-tab>
        </template>
      </van-tabs>
    </div>

    <!--  -->
    <div class="content">
      <template v-for="(value, key, index) in allCities">
        <city-group v-show="tabAcitve === key" :group-data="value" />
      </template>
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from "vue";
import { useRouter } from "vue-router";
import { getCityAll } from "@/services";
import { storeToRefs } from "pinia";
import useCityStore from "@/stores/modules/city";

import CityGroup from "./cpns/city-group.vue";

const router = useRouter();

// 搜索框的功能
const searchValue = ref("");
const cancelClick = () => {
  router.push("/home");
};

// tab的切换
const tabAcitve = ref();

// 从store中拿数据
const cityStore = useCityStore();
cityStore.fetchAllCitiesData();
const { allCities } = storeToRefs(cityStore); //响应式

// 获取选中标签后的数据
const currentGroup = computed(() => allCities.value[tabAcitve.value]);
</script>

<style lang="less" scoped>
.city {
  .top {
    position: relative;
    z-index: 9;
  }
  .content {
    height: calc(100vh - 98px);
    overflow-y: auto;
  }
}
</style>